package day3.p5;

@SuppressWarnings("unused")
public class BankAccount {
	private int accNo;
	private String custName;
	private String accType; // (indicates ‘Savings’ or ‘Current’)
	private float balance;

	public BankAccount() {
	}

	public BankAccount(int accNo, String custName, String accType, float balance) {
		try {
			this.accNo = accNo;
			this.custName = custName;
			this.accType = accType;
			if (balance < 0)
				throw new NegativeAmount();
			else if (accType.equalsIgnoreCase("Savings") && balance < 1000)
				throw new LowBalanceException();
			else if (this.accType.equalsIgnoreCase("Current")
					&& this.balance < 5000) throw new LowBalanceException();
			this.balance = balance;
		} catch (NegativeAmount e) {
			System.out.println(e.toString());
		} catch (LowBalanceException e) {
			System.out.println(e.toString());
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}

	public void deposit(float amt) {
		try {
			if (amt < 0)
				throw new NegativeAmount();
			else
				this.balance += amt;
		} catch (NegativeAmount e) {
			System.out.println(e.toString());
		}
	}

	public void withdraw(float amt) {
		try {
			if (amt < 0)
				throw new NegativeAmount();
			else
				this.balance -= amt;
			if (this.accType.equalsIgnoreCase("Savings") && this.balance < 1000) {
				this.balance += amt;
				throw new InsufficientFunds();
			} else if (this.accType.equalsIgnoreCase("Current")
					&& this.balance < 5000) {
				this.balance += amt;
				throw new InsufficientFunds();
			}

		} catch (NegativeAmount e) {
			System.out.println(e.toString());
		} catch (InsufficientFunds e) {
			System.out.println(e.toString());
		} catch (Exception e) {
			System.out.println(e.toString());
		}
	}

	public float getBalance() {
		try {
			if (this.accType.equalsIgnoreCase("Savings") && this.balance < 1000)
				throw new LowBalanceException();
			else if (this.accType.equalsIgnoreCase("Current")
					&& this.balance < 5000) throw new LowBalanceException();
		} catch (LowBalanceException e) {
			System.out.println(e.toString());
		} catch (Exception e) {
			System.out.println(e.toString());
		}
		return this.balance;
	}
}
